package gclib.engine;

import gclib.entities.Effect;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author Jason
 */
public class EffectFactory {
	private enum WORD_TYPE {OPERATORS};
	private static final String OP = "OPERATOR";
	private static Set<String> OPERATORS = new HashSet<String>(){
		{
			add("gain");
			add("takes");
		}
	};
	private static Set<String> CONDITIONAL = new HashSet<String>(){
		{
			add("while");
			add("While");
			add("when");
			add("When");
			add("if");
			add("If");
			add("provoke");
		}
	};
	private static Set<String> STATE = new HashSet<String>(){
		{
			add("bloodied");
			add("charging");
			add("charge");
			add("opportunity attack");
		}
	};

    private EffectFactory() {
    }

	public static Set<Effect> processText(String flavorText){
		String[] sentences = flavorText.split("\\.");
		Set<Effect> effects = new HashSet<Effect>(sentences.length);
		Effect effect;
		for(String sentence:sentences){
			effect = new Effect();

			String[] words = sentence.trim().split("[ ,]");
			String[][] wordMap = loadWordMap(words);
		}

		return null;
	}

	private static String[][] loadWordMap(String[] words){
		String[][] wordMap = new String[words.length][2];
		int keyWordCount = 0;
		for (int wordIndex = 0; wordIndex < words.length; wordIndex++) {
			keyWordCount++;
			String word = words[wordIndex];
			wordMap[wordIndex][0] = word;
			if(OPERATORS.contains(word)){
				wordMap[wordIndex][1] = OP;
				continue;
			}
			if(STATE.contains(word)){
				wordMap[wordIndex][1] = "state";
				continue;
			}
			if(CONDITIONAL.contains(word)){
				wordMap[wordIndex][1] = "conditional";
				continue;
			}
			wordMap[wordIndex][1] = "none";
			keyWordCount--;
		}
		String[][] simpleMap = new String[keyWordCount][2];
		keyWordCount = 0;
		for (int simpleMapIndex = 0; simpleMapIndex < wordMap.length; simpleMapIndex++) {
			if(!wordMap[simpleMapIndex][1].equals("none")){
				String[] strings = wordMap[simpleMapIndex];
				simpleMap[keyWordCount][0] = strings[0];
				simpleMap[keyWordCount][1] = strings[1];
				keyWordCount++;
			}
		}
		return wordMap;
	}

    public static EffectFactory getInstance() {
        return EffectFactoryHolder.INSTANCE;
    }


    private static class EffectFactoryHolder {
        private static final EffectFactory INSTANCE = new EffectFactory();
    }
 }
